package com.miaoshaproject;

import com.miaoshaproject.dao.UserDOMapper;
import com.miaoshaproject.dataproject.UserDO;
import com.miaoshaproject.lender.credit.CreditService;
import com.miaoshaproject.lender.ServiceLocator;
import com.miaoshaproject.log.OperationLog;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Hello world!
 *
 */
@SpringBootApplication(scanBasePackages = {"com.miaoshaproject"})
@RestController
@MapperScan("com.miaoshaproject.dao")
// 启用AOP
@EnableAspectJAutoProxy
public class App {
//    注入UserMapper
    @Autowired
    private UserDOMapper userDOMapper;

    @Autowired
    private ServiceLocator serviceLocator;

    @RequestMapping(value = "/credit")
    @OperationLog(module = "授信", type = "DEFAULT", bizId = "12345")
    public void credit(){
        // 动态路由到具体实现
        CreditService service = serviceLocator.route("ID", "ATOME");
        System.out.println(service.submitForm());
    }

    private void process() {
        String routeKey = "ID_ATOME";
        CreditService service = serviceLocator.route(routeKey);
    }


    @RequestMapping(value = "/test")
    @OperationLog(module = "测试", type = "DEFAULT", bizId = "12345")
    public String test(){
        UserDO userD0= userDOMapper.selectByPrimaryKey(1);
        if(userD0==null){
            return "Hello SpringBoot,用户对象不存在";
        }else{
            return userD0.getName();
        }
    }


    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
        SpringApplication.run(App.class,args);
    }
}
